package com.cskaoyan.service;

import com.cskaoyan.bean.MarketCollect;
import com.cskaoyan.bean.MarketFootprint;
import com.cskaoyan.bean.MarketFootprintExample;
import com.cskaoyan.bean.common.BasePageInfo;
import com.cskaoyan.bean.common.CommonData;
import com.cskaoyan.mapper.MarketFootprintMapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author yi
 * @date 2022/10/13 17:56
 */
@Service
public class AdminFootprintServiceImpl implements AdminFootprintService {
    @Autowired
    MarketFootprintMapper marketFootprintMapper;

    @Override
    public CommonData<MarketFootprint> queryFootprint(Integer userId, Integer goodsId, BasePageInfo basePageInfo) {
        PageHelper.startPage(basePageInfo.getPage(), basePageInfo.getLimit());
        MarketFootprintExample marketFootprintExample = new MarketFootprintExample();
        marketFootprintExample.setOrderByClause(basePageInfo.getSort());
        MarketFootprintExample.Criteria criteria = marketFootprintExample.createCriteria();
        criteria.andDeletedEqualTo(false);
        if (userId != null) {
            criteria.andUserIdEqualTo(userId);
        }
        if (goodsId != null) {
            criteria.andGoodsIdEqualTo(goodsId);
        }

        List<MarketFootprint> marketFootprints = marketFootprintMapper.selectByExample(marketFootprintExample);
        PageInfo<MarketFootprint> marketFootprintPageInfo = new PageInfo<>(marketFootprints);
        return CommonData.data(marketFootprintPageInfo);
    }
}
